/*
 * @LastEditors: yuSeen
 * @LastEditTime: 2021-12-29 19:04:23
 * 天凉好个秋
 */
export const useView = () => {
    /**
     * @description: 关键字高亮
     * @param {string} str  源文字
     * @param {string} keyword  需要高亮的文字
     * @param {string} color    高亮颜色
     * @return {*}  html字符串
     */    
    const keywordHighLight = (str: string, keyword: string, color: string = '#507db5') => {
        if(str.indexOf(keyword) !== -1 && keyword !== '' ){
            const reg = new RegExp(keyword,"g");
            return str.replace(reg, `<span style="color:${color};">${keyword}</span>`);
      }else{
            return str;
      }
    }

    return {
        keywordHighLight
    }
}